package com.zzz.web.Servlet;

import com.google.gson.Gson;
import com.zzz.web.DB.GetContext;
import com.zzz.web.DB.MyConfig;
import com.zzz.web.Data.NewRssi;
import com.zzz.web.Data.RSSI;
import com.zzz.web.Data.XYaxis;
import com.zzz.web.service.NewRssiService;
import com.zzz.web.service.RssiService;
import com.zzz.web.service.XYService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class GetXY extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String status = req.getParameter("status");

        ApplicationContext context = GetContext.getContext();

        String respJson = null;
        if(status.equals("PLACE1")){
            List<XYaxis> xyList = context.getBean("XYService", XYService.class).selectAll();
            respJson = new Gson().toJson(xyList);

        }
        if(status.equals("PLACE2")){
            List<XYaxis> xyList = context.getBean("XYService", XYService.class).selectAllFrom2();
            respJson = new Gson().toJson(xyList);

        }
        if(status.equals("RSSIDATA")){
            List<NewRssi> newRssis = context.getBean("newRssiService", NewRssiService.class).selectAll();
            respJson = new Gson().toJson(newRssis);
        }
        if(status.equals("RSSI")){
            List<RSSI> Rssis = context.getBean("rssiService", RssiService.class).all();
            respJson = new Gson().toJson(Rssis);
        }

        resp.getWriter().write(respJson);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
